{% extends "base.html" %}
{% load staticfiles %}

{% block content %}
  {% block message_info_homepage %}{% endblock %}

  {% for object in object_list %}
    <div class="post">
      <h2><a href="{% url 'detail_post_page' slug=object.slug %}">{{ object.title }}</a></h2>
      <p class="meta">
        By: <a href="{% url 'author_posts_page' username=object.author.user.username %}" style="text-transform:uppercase">{{ object.author }}</a> &#9679;
        at {{ object.created }} &#9679;
        Posted under:
        {% for tag in object.tags.all %}
          <a href="{% url 'tag_posts_page' slug=tag.slug %}">#{{ tag }}</a>{% if not forloop.last %}, {% endif %}
        {% empty %}Uncategories
        {% endfor %}
      </p>

      {% if object.cover %}
        <div class="cst__cover__posts">
          <a href="{% url 'detail_post_page' slug=object.slug %}">
            <img style="width:100%" src="/media/{{ object.cover }}" alt="{{ object.title }}" title="{{ object.title }}">
          </a>
        </div>
      {% endif %}
      {{ object.description|safe|striptags|truncatewords:"50"|linebreaks }}
      <span style="margin-bottom: .5em;float:right">
        <a href="{% url 'detail_post_page' slug=object.slug %}">Read More &rarr;</a>
      </span>
      <div style="clear:both;border-bottom: 1px solid #F2F2F2;margin: 10px 0"></div>
    </div>
  {% empty %}
    <p class="alert alert-warning text-center cst__radus"><span class="glyphicon glyphicon-info-sign"></span> Posts does not exist!</p>
  {% endfor %}

  {% if is_paginated %}
    {% if request.GET.q %}
      <ul class="pagination">
        <li {% if not page_obj.has_previous %}class="disabled"{% endif %}>
          <a {% if page_obj.has_previous %}href="?q={{ query }}&amp;page={{ page_obj.previous_page_number }}" aria-label="Previous" {% endif %}><span aria-hidden="true">&laquo;</span></a>
        </li>
        <li><a href="?q={{ query }}&amp;page=1">First</a></li>
        {% for linkpage in page_range %}
        {% ifequal linkpage page_obj.number %}
        <li class="active">
          <a>{{ page_obj.number }}<span class="sr-only">(current)</span></a>
        </li>
        {% else %}
        <li><a href="?q={{ query }}&amp;page={{ linkpage }}">{{ linkpage }}</a></li>
        {% endifequal %}
        {% endfor %}
        <li><a href="?q={{ query }}&amp;page={{ page_obj.paginator.num_pages }}">Last</a></li>
        <li {% if not page_obj.has_next %}class="disabled"{% endif %}>
          <a {% if page_obj.has_next %}href="?q={{ query }}&amp;page={{ page_obj.next_page_number }}" aria-label="Next" {% endif %}><span aria-hidden="true">&raquo;</span></a>
        </li>
      </ul>
    {% else %}
      <ul class="pagination">
        <li {% if not page_obj.has_previous %}class="disabled"{% endif %}>
          <a {% if page_obj.has_previous %}href="?page={{ page_obj.previous_page_number }}" aria-label="Previous" {% endif %}><span aria-hidden="true">&laquo;</span></a>
        </li>
        <li><a href="?page=1">First</a></li>
        {% for linkpage in page_range %}
        {% ifequal linkpage page_obj.number %}
        <li class="active">
          <a>{{ page_obj.number }}<span class="sr-only">(current)</span></a>
        </li>
        {% else %}
        <li><a href="?page={{ linkpage }}">{{ linkpage }}</a></li>
        {% endifequal %}
        {% endfor %}
        <li><a href="?page={{ page_obj.paginator.num_pages }}">Last</a></li>
        <li {% if not page_obj.has_next %}class="disabled"{% endif %}>
          <a {% if page_obj.has_next %}href="?page={{ page_obj.next_page_number }}" aria-label="Next" {% endif %}><span aria-hidden="true">&raquo;</span></a>
        </li>
      </ul>
    {% endif %}{# endif request.GET.q #}
  {% endif %}
{% endblock %}
